--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_CPT_TVAART AS (SELECT * FROM &erp.CPT_TVAART WHERE 1=2);




DELETE FROM se_CPT_TVAART;

 INSERT INTO se_CPT_TVAART
 (SELECT id tvaart_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle tvaart_lib,
         NULL tvaart_lib2,
         'T' tiers_typ
    FROM uv_ctvaart) ;



 UPDATE se_CPT_TVAART tf SET enreg_id=(select enreg_id FROM &erp.CPT_TVAART f WHERE f.tvaart_cod=tf.tvaart_cod) ;
 UPDATE se_CPT_TVAART tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('tvaart_cod','CPT_TVAART','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source, tvaart_cod, enreg_id, enreg_s, tvaart_lib, tvaart_lib2, tiers_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_CPT_TVAART g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.CPT_TVAART g
  )
GROUP BY  tvaart_cod, enreg_id, enreg_s, tvaart_lib, tvaart_lib2, tiers_typ
HAVING Count(1)!=2) r
ORDER BY tvaart_cod;